package com.taotao.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSONObject;
import com.taotao.common.resp.EasyUiResult;
import com.taotao.common.resp.TaotaoResult;
import com.taotao.pojo.Item;
import com.taotao.pojo.User;
import com.taotao.service.ItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by zzb on 2017/11/2.
 */
@Controller
@RequestMapping("/item")
@Slf4j
public class ItemController {



    //@Autowired
    @Reference
    private ItemService itemService;


    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public EasyUiResult itemList(@RequestParam(value = "page",defaultValue = "1") Integer page,
                                 @RequestParam(value = "rows",defaultValue = "30") Integer rows) {

        EasyUiResult result = itemService.findAllByPage(page,rows);

        return result;
    }


    @RequestMapping(value = "/save",method = RequestMethod.POST)
    @ResponseBody
    public TaotaoResult itemSave(Item item,
                                 @RequestParam(value = "desc") String desc) {

        try {
            TaotaoResult result = itemService.save(item,desc);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            TaotaoResult result = new TaotaoResult();
            result.setStatus(500);
            result.setMsg("error to save item");
            return result;
        }
    }







}
